/**
 * Project Name:gc_sms_hss
 * File Name:EmployeeStatusController.java
 * Package Name:com.clps.dev.sms.controller.sm
 * Copyright (c) 2018, erwin.wang@clpsglobal.com All Rights Reserved.
 *
 */
package com.clps.dev.sms.controller.sm;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.clps.dev.sms.common.CommonData;
import com.clps.dev.sms.common.result.ResponseResult;
import com.clps.dev.sms.common.result.ResultState;
import com.clps.dev.sms.common.result.ResultType;
import com.clps.dev.sms.entity.sm.EmployeeStatus;
import com.clps.dev.sms.service.sm.IEmployeeStatusService;
import com.clps.dev.sms.util.factory.ToolFactory;
import com.clps.dev.sms.util.result.ResponseResultUtil;

/**
 * ClassName: EmployeeStatusController <br/>
 * Description: 员工状态控制层负责员工状态信息操作
 * 
 * @author erwin.wang
 * @version V1.0
 * @since JDK 1.8
 * @date 2018-12-12 09:48:57
 */
@Controller
@RequestMapping(value = "/es")
public class EmployeeStatusController {

	@Resource
	private IEmployeeStatusService iess;

	private Logger logger = Logger.getLogger(EmployeeStatusController.class);

	//private List<EmployeeStatus> ess;

	private ResponseResult<EmployeeStatus> responseResult;

	 	@GetMapping(value="/list")
	    public String jumpToPersonPage(){
	    	System.out.println("jump employee_status!");
	    	return "/sm/employee_status";
	    }
	
	/**
	 * addEmployeeStatus:新增员工状态信息
	 * 					
	 * @param es 员工状态对象
	 * @return ResponseResult<EmployeeStatus> 返回员工状态的响应结果对象信息
	 */
	@ResponseBody
	@PostMapping(value = "/es")
	public ResponseResult<EmployeeStatus> addEmployeeStatus(@RequestBody EmployeeStatus es) {
		if (es.getEmployeeStatusName() == null || es.getEmployeeStatusCreatedEmployeeId() == null
				|| es.getEmployeeStatusCreatedTime() == null) {
			logger.debug(ResultType.INPUT_NULL);
			this.responseResult =ResponseResultUtil.error(ResultState.NOT_ACCEPTABLE, ResultType.INPUT_NULL);
		} else {
			es.setEmployeeStatusCreatedEmployeeId(1);
			es.setEmployeeStatusCreatedTime(ToolFactory.getDateInstance(CommonData.YYYY_MM_DD_HH_MM_SS));
			es.setEmployeeStatusUpdatedEmployeeId(1);
			this.responseResult = iess.addEmployeeStatus(es);
		}
		return responseResult;
	}

	@ResponseBody
	@GetMapping(value = "/es")
	public ResponseResult<EmployeeStatus> getAllEmployeeStatus() {
		this.responseResult = iess.queryAllEmployeeStatus();
		logger.info("---------------"+this.responseResult.getData().toString());
		responseResult.setState(ResultState.OPERATIONSUCCESS);
		return responseResult;
	}

	@PutMapping(value = "/es/{esId}")
	public String editEmployeeStatus(@PathVariable("esId") String esId, Model model) {
		int esid = Integer.parseInt(esId);
		ResponseResult<EmployeeStatus> responseResult = iess.queryEmployeeStatus(esid);
		EmployeeStatus employeeStatus = (EmployeeStatus) responseResult.getData();
		model.addAttribute("employeeStatus", employeeStatus);
		return "redirect:/sm/es";
	}

}
